package com.cip.master.dao.impl;

import java.util.List;
import java.util.Set;

import com.cip.admin.dao.impl.CipHibernateDAOSupport;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.cip.master.dao.ExaminationDAO;
import com.cip.master.model.ExamPaper;
import com.cip.master.model.Examination;

public class ExaminationDAOImpl extends CipHibernateDAOSupport implements ExaminationDAO{

	public List<Examination> getAllExamList() throws Exception {
		HibernateTemplate hibernateTemplate = getCipHibernateTemplate();		
	    List<Examination> examList = hibernateTemplate.loadAll(Examination.class);
		return examList;
	}

	public Examination getExamById(int id) throws Exception {
		HibernateTemplate hibernateTemplate = getHibernateTemplate();
		 return hibernateTemplate.get(Examination.class, id);
	}

	public Examination saveOrUpdateExam(Examination exam) throws Exception {
		getHibernateTemplate().saveOrUpdate(exam);
		return exam;
	}

	public Examination editExam(Examination exam) throws Exception {
		getHibernateTemplate().update(exam); 
		return exam;
	}
	
	public Examination getExamByName(String name) throws Exception {
		String query="select exam from Examination as exam where exam.examName='"+name+"'";
		return (Examination)getCipHibernateTemplate().find(query).get(0);
	}
	
	public List<Examination> getAllExamListByClass(String classId) throws Exception {
		System.out.println("class===>"+classId);
		String queryString="select exam from Examination as exam where exam.classYear='"+classId+"'";
		HibernateTemplate hibernateTemplate = getCipHibernateTemplate();		
	    List<Examination> examList = hibernateTemplate.find(queryString);
		return examList;
	}
	
	public List<ExamPaper> getExamPapersByExam(int examId) throws Exception{
		String query="select exam.examPapers from Examination as exam where exam.id='"+examId+"'";
		List<ExamPaper> examPapers =  getCipHibernateTemplate().find(query);
		return examPapers;
	}
}
